package com.vallis.lottery.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vallis.common.annotation.Log;
import com.vallis.common.core.controller.BaseController;
import com.vallis.common.core.domain.AjaxResult;
import com.vallis.common.enums.BusinessType;
import com.vallis.lottery.domain.StandardTicket;
import com.vallis.lottery.service.IStandardTicketService;
import com.vallis.common.utils.poi.ExcelUtil;
import com.vallis.common.core.page.TableDataInfo;

/**
 * 标准票库Controller
 *
 * @author vallis
 * @date 2022-08-12
 */
@RestController
@RequestMapping("/standard_ticket/standard_ticket")
public class StandardTicketController extends BaseController
{
    @Autowired
    private IStandardTicketService standardTicketService;

    /**
     * 查询标准票库列表
     */
    @PreAuthorize("@ss.hasPermi('standard_ticket:standard_ticket:list')")
    @GetMapping("/list")
    public TableDataInfo list(StandardTicket standardTicket)
    {
        startPage();
        List<StandardTicket> list = standardTicketService.selectStandardTicketList(standardTicket);
        return getDataTable(list);
    }

    /**
     * 导出标准票库列表
     */
    @PreAuthorize("@ss.hasPermi('standard_ticket:standard_ticket:export')")
    @Log(title = "标准票库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StandardTicket standardTicket)
    {
        List<StandardTicket> list = standardTicketService.selectStandardTicketList(standardTicket);
        ExcelUtil<StandardTicket> util = new ExcelUtil<StandardTicket>(StandardTicket.class);
        util.exportExcel(response, list, "标准票库数据");
    }

    /**
     * 获取标准票库详细信息
     */
    @PreAuthorize("@ss.hasPermi('standard_ticket:standard_ticket:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(standardTicketService.getById(id));
    }

    /**
     * 新增标准票库
     */
    @PreAuthorize("@ss.hasPermi('standard_ticket:standard_ticket:add')")
    @Log(title = "标准票库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StandardTicket standardTicket) {
        return toAjax(standardTicketService.save(standardTicket));
    }

    /**
     * 修改标准票库
     */
    @PreAuthorize("@ss.hasPermi('standard_ticket:standard_ticket:edit')")
    @Log(title = "标准票库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StandardTicket standardTicket) {
        return toAjax(standardTicketService.updateById(standardTicket));
    }

    /**
     * 删除标准票库
     */
    @PreAuthorize("@ss.hasPermi('standard_ticket:standard_ticket:remove')")
    @Log(title = "标准票库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(standardTicketService.removeByIds(Arrays.asList(ids)));
    }
}
